home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ezhint.exe / EZHINT.CPP < prev    next >
C/C++ Source or Header  |  1992-12-09  |  3KB  |  118 lines

  1. #define Uses_TApplication
  2. #define Uses_TStatusLine
  3. #define Uses_TStatusDef
  4. #define Uses_TStatusItem
  5. #define Uses_TMenu
  6. #define Uses_TMenuBar
  7. #define Uses_TMenuItem
  8. #define Uses_TSubMenu
  9. #define Uses_TKeys
  10. #define Uses_Strings
  11. #include <tv.h>
  12.  
  13. #include "strings.h"
  14.  
  15. const    cmAbout     = 1000,
  16.         cmFileNew     = 1001;
  17.  
  18. const    hcSystem    = 1000,
  19.         hcAbout        = 1001,
  20.         hcFile        = 1002,
  21.         hcFileExit    = 1003,
  22.         hcFileNew    = 1004;
  23.  
  24. static StrRef strRef[] = {
  25.     { hcSystem,                "system commands" },
  26.     { hcAbout,                "show version and copyright information" },
  27.     { hcFile,                "file-management commands (Open, Save, etc)" },
  28.     { hcFileExit,            "exit the program" },
  29.     { hcFileNew,            "create a new file in a new Edit window" },
  30.     { srNull,                0 }
  31.     };
  32.  
  33. class THintStatusLine : public TStatusLine
  34.     {
  35.     public:
  36.  
  37.         THintStatusLine( const TRect& bounds, TStatusDef& aDefs ) :
  38.             TStatusLine( bounds, aDefs )
  39.             {
  40.             s.load(strRef);
  41.             };
  42.  
  43.         virtual const char* hint( ushort aHelpCtx );
  44.  
  45.     protected:
  46.  
  47.         Strings s;
  48.     };
  49.  
  50. const char* THintStatusLine::hint( ushort aHelpCtx )
  51.     {
  52.     char *p = s[aHelpCtx];
  53.     if( p == 0 )
  54.         return TStatusLine::hint(aHelpCtx);
  55.     else
  56.         return p;
  57.     }
  58.  
  59. class TApp : public TApplication
  60.     {
  61.     public:
  62.  
  63.         TApp() : TProgInit(initStatusLine, initMenuBar, initDeskTop)
  64.             {}
  65.  
  66.         static TMenuBar *initMenuBar( TRect );
  67.         static TStatusLine *initStatusLine( TRect );
  68.     };
  69.  
  70. TMenuBar *TApp::initMenuBar( TRect r )
  71.     {
  72.     r.b.y = r.a.y+1;
  73.  
  74.     TSubMenu& sub1 = *new TSubMenu( "~≡~", kbAltSpace, hcSystem ) +
  75.         *new TMenuItem( "~A~bout...", cmAbout, 0, hcAbout, 0, 0 );
  76.  
  77.     TSubMenu& sub2 = *new TSubMenu( "~F~ile", kbNoKey, hcFile ) +
  78.         *new TMenuItem( "~N~ew", cmFileNew, kbNoKey, hcFileNew, 0 )+
  79.         newLine() +
  80.         *new TMenuItem( "E~x~it", cmQuit, kbAltX, hcFileExit, "Alt-X" );
  81.  
  82.     TMenuBar *menuBar = new TMenuBar( r, new TMenu((TMenuItem &) (
  83.         sub1 + sub2)));
  84.  
  85.     return menuBar;
  86.     }
  87.  
  88. TStatusLine *TApp::initStatusLine( TRect r )
  89.     {
  90.     r.a.y = r.b.y-1;
  91.  
  92.     return new THintStatusLine( r,
  93.         *new TStatusDef( hcSystem, hcFileNew )+
  94.             *new TStatusItem( "~F1~ Help", kbF1, cmHelp )+
  95.             *new TStatusItem( 0, kbAltX, cmQuit )+
  96.             *new TStatusItem( 0, kbAltF3, cmClose )+
  97.             *new TStatusItem( 0, kbF5, cmZoom )+
  98.             *new TStatusItem( 0, kbCtrlF5, cmResize )+
  99.             *new TStatusItem( 0, kbF10, cmMenu )+
  100.  
  101.         *new TStatusDef( 0, 0xFFFF )+
  102.             *new TStatusItem( "~F1~ Help", kbF1, cmHelp )+
  103.             *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit )+
  104.             *new TStatusItem( 0, kbAltF3, cmClose )+
  105.             *new TStatusItem( 0, kbF5, cmZoom )+
  106.             *new TStatusItem( 0, kbCtrlF5, cmResize )+
  107.             *new TStatusItem( 0, kbF10, cmMenu )
  108.         );
  109.     }
  110.  
  111. int main()
  112.     {
  113.     TApp app;
  114.     app.run();
  115.     app.shutDown();
  116.     return 0;
  117.     }
  118.